import cTitle from "components/title";
import { Toast } from 'vant';
import diyBackGround from "../member/balance/componet/diyBackGround.vue";

var isclick = true;

export default {
  data() {
    return {
      //爱心转账值
      sell_value: "",
      //爱心会员ID
      sell_id: "",
      // 转让手续费比率
      poundage: 0,
      trading_limit: 0,
      trading_fold: 0,

      love_name: "", //爱心值自定义名称
      balance_name: "", //爱心值自定义名称
      usable: 0, // 登陆会员可用爱心值
      rate: 0,

      isTransformActive: false, //判断是否为转化爱心值
      balanceLang: "" //金额自定义
    };
  },
  methods: {
    getUsable() {
      if (this.isTransformActive) {
        $http
          .get("plugin.sign-buy.frontend.balance.member-balance", {}, "加载中")
          .then(
            response => {
              if (response.result === 1) {
                this.love_name = response.data.active_value_name;
                this.usable = response.data.credit2;
              } else {
                this.$dialog.alert({message:response.msg});
              }
            },
            function(response) {
              this.$dialog.alert({message:response.msg});
            }
          );
      } else {
        $http.get("plugin.sign-buy.frontend.balance.member-active", {}, "加载中").then(
          response => {
            if (response.result === 1) {
              this.love_name = response.data.active_value_name;
              this.usable = response.data.credit2;
              this.fun.setWXTitle("资产转化");
            } else {
              this.$dialog.alert({message:response.msg});
            }
          }

        );
      }
    },
    allConversion(){
      this.sell_value = this.usable ;
    },
    saleBalance() {
      if (!this.sell_value) {
        Toast("请输入您要转化的数额");
        return;
      }
      if(isclick) {
        isclick= false;
        let trading_url;

        trading_url = "plugin.sign-buy.frontend.balance.convert-deduct";
        if (this.isTransformActive) {
          trading_url = "plugin.sign-buy.frontend.balance.convert-give";
        }
        $http
          .get(
            trading_url,
            {
              convert_amount: this.sell_value
            },
            "加载中"
          )
          .then(
            response => {
              setTimeout(function(){
                isclick = true;
              }, 1000);
              if (response.result === 1) {
                this.$dialog.alert({message:response.msg});
                this.sell_value = "";
                this.getUsable();
              } else {
                this.$dialog.alert({message:response.msg});
              }
            },
            function(response) {
              setTimeout(function(){
                isclick = true;
              }, 1000);
              this.$dialog.alert({message:response.msg});
            }
          );
        }
      }
  },
  activated() {
    this.balanceLang = this.fun.getBalanceLang(); //获取金额自定义
    this.isTransformActive = this.$route.name != "sign_in_subscribe_trading_b" ? true : false;
    console.log(this.isTransformActive,'ddddddddd')
    this.getUsable();
  },
  components: { cTitle,diyBackGround }
};
